package cn.kickegg.concurrent.executor;

import java.io.File;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author KickEGG
 * @createTime 2018-07-30 19:09
 * @Description
 */
public class FileSearchPlus {

  public static volatile int count = 0;

  public static void main(String[] args) {

    long start, end;
    start = System.currentTimeMillis();

    //创建一个可重用固定线程数的线程池
    ExecutorService pool=Executors.newFixedThreadPool(5);
//
//    Thread t1=new MyThread();
//
//    Thread t2=new MyThread();
//
//    Thread t3=new MyThread();
//
//    Thread t4=new MyThread();
//
//    Thread t5=new MyThread();

    //将线程放到池中执行；
//
//    pool.execute(t1);
//
//    pool.execute(t2);
//
//    pool.execute(t3);
//
//    pool.execute(t4);
//
//    pool.execute(t5);

    //关闭线程池

    pool.shutdown();


    //路径   这里写一个路径进去
    String path = "D:\\Bank\\PRIVATE\\Prj.X\\EggCluster";
    //调用方法
    getFiles(path);
    end = System.currentTimeMillis();
    System.out.println("start time:" + start + "; end time:" + end + "; Run Time:" + (end - start) + "(ms)" + " counts:" + count);
  }

  /**
   * 递归获取某路径下的所有文件，文件夹，并输出
   */

  public static void getFiles(String path) {
    File file = new File(path);
    // 如果这个路径是文件夹
    if (file.isDirectory()) {
      // 获取路径下的所有文件
      File[] files = file.listFiles();
      for (int i = 0; i < files.length; i++) {
        // 如果还是文件夹 递归获取里面的文件 文件夹
        if (files[i].isDirectory()) {
          System.out.println("目录：" + files[i].getPath());
          getFiles(files[i].getPath());
          count++;
        } else {
          System.out.println("文件：" + files[i].getPath());

        }

      }
    } else {
      System.out.println("文件：" + file.getPath());

    }

  }

}
